package org.liquidByte.simpleChat.server;


import org.liquidByte.simpleChat.communication.Channel;
import org.liquidByte.simpleChat.dto.User;

class UserChannel {
	private User user;
	private EventClient eventClient;
	private Channel channel;
	
	public UserChannel(User user, Channel channel) {
		if (user == null) {
			throw new NullPointerException("user is null");
		}
		if (channel == null) {
			throw new NullPointerException("channel is null");
		}
		this.user = user;
		this.channel = channel;
	}
	
	public Channel getChannel() {
		return channel;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public EventClient getEventClient() {
		if (this.eventClient == null) {
			this.eventClient = new EventClient(this.channel);
		}
		return eventClient;
	}

	@Override
	public int hashCode() {
		return this.channel.hashCode();
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UserChannel other = (UserChannel) obj;
		if (channel == null) {
			if (other.channel != null)
				return false;
		} else if (!channel.equals(other.channel))
			return false;
		return true;
	}
}
